function addFlexPackage(){
	waitingDialog({});
	$("#addtableFlex").attr("style","display:;");
	$("#addtableFlex").load("/adminconsole/PriceManager/addflexiblepackage.jsp",function(responseText, textStatus, XMLHttpRequest) {
		$("#tableFlex").attr("style","display:none");
		$("#suggest").html(addpackage);
		loadAddFlexiblepackageData();
		callDatePicker();
	});
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function editFlexPackege(id){
	debugger;
	if($("#tabHeader_1").attr("class") == "tabActiveHeader"){
		$("#addtableFlex").attr("style","display:;");
		$("#addtableFlex").load("/adminconsole/PriceManager/addflexiblepackage.jsp",function(responseText, textStatus, XMLHttpRequest) {
			$("#tableFlex").attr("style","display:none");
			$("#suggest").html(editpackage);
			loadAddFlexiblepackageData(id);
			callDatePicker();
		});
	}else{
		$("#addtableFlexArchived").attr("style","display:;");
		$("#addtableFlexArchived").load("/adminconsole/PriceManager/addflexiblepackage.jsp",function(responseText, textStatus, XMLHttpRequest) {
			$("#tableFlexArchived").attr("style","display:none");
			$("#suggest").html(editpackage);
			loadAddFlexiblepackageData(id);
			callDatePicker();
		});
	}
}

function loadAddFlexiblepackageData(id){
	var data = {func : "getflexiblepackagedata",id:id};
	var url = "/flexiblepackageservice";
	simpleservice(url,data,fillData);
}

function callDatePicker(){
	$(function() {
		$("#from").datepicker({
	    	dateFormat: 'yy-mm-dd',
	    	minDate: new Date(getServerDateTime()),
	    	onSelect: function(DATE)
			{
				$('#from').val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
				$('#from').attr('date',DATE);
				$( "#to").datepicker( "option", "minDate", DATE);
			}
	    });
	  });
	$(function() {
	    $( "#to" ).datepicker({
	    	dateFormat: 'yy-mm-dd',
	    	onSelect: function(DATE)
			{
				$('#to').val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
				$('#to').attr('date',DATE);
			}
	    });
	  });
}

var SharedData ={};
function fillData(data){
	var objArray = new Array();
	objArray = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray);
	if(checkLogOut)
		return;
	SharedData.Roomtype = objArray['roomtype'];
	renderGuestType(objArray['guesttype']);
	renderRoomType(objArray['roomtype']);
	loadDatepicker();
	if(objArray["data"] != null){
		fillPackageData(objArray["data"]);
	}
}

function fillPackageData(objArray){
	$("[type=button][name=save]").attr("onClick","addflexiblepackage('"+objArray['id']+"')")
	$("#packagename").val(objArray["PackageName"]);
	$("#roomtype").val(objArray["RoomType"]);
	$("#description").val(objArray["Description"]);
	checkedAvaliable(objArray["AvaliableFor"]);
	$("#from").val(new Date(objArray["From"]).getFormatedString());
	$("#from").attr("date",new Date(objArray["From"]).toSystemFormat());
	$("#to").val(new Date(objArray["To"]).getFormatedString());
	$("#to").attr("date",new Date(objArray["To"]).toSystemFormat());
	checkedPackageControl(objArray["PackageControl"]);
	searchdate();
	fillSubPackage(objArray["SubPackage"]);
}

function checkedAvaliable(objArray){
	for(var i =0;i<objArray.length;i++){
		$("[name=gtype][value="+objArray[i]+"]").attr("checked",true);
	}
}

function checkedPackageControl(objArray){
	var value = "off";
	if(objArray){
		value = "on";
	}
	$("[g=control][value="+value+"]").attr("checked",true);
}

function fillSubPackage(objArray){
	for(var i=0;i<objArray.length;i++){
		var systemDate = new Date(objArray[i]['date']).toSystemFormat();
		$("[name=rttable][date="+systemDate+"]").attr("pId",objArray[i]['id'])
		$("[name=rttable][date="+systemDate+"]").find("[group=pricepernight]").val(objArray[i]['pricepernight']);
		$("[name=rttable][date="+systemDate+"]").find("[group=upchargeperson]").val(objArray[i]['upchargeperperson']);
		$("[name=rttable][date="+systemDate+"]").find("[group=extrabedprice]").val(objArray[i]['extrabed']);
		$("[name=rttable][date="+systemDate+"]").find("[name=adult]").val(objArray[i]['adult']);
		$("[name=rttable][date="+systemDate+"]").find("[name=child]").val(objArray[i]['child']);
		$("[name=rttable][date="+systemDate+"]").find("[name=breakfast]").attr("checked",objArray[i]['inclusiveBreakfast']);
	}
}

function loadDatepicker(){
	$("#datefrom").datepicker({
		dateFormat: 'yy-mm-dd',
		onSelect: function(DATE)
			{
				$('#datefrom').val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
				$('#datefrom').attr('date',DATE);
				$( "#dateto").datepicker( "option", "minDate", DATE);
			}
	});
	$("#dateto").datepicker({
		dateFormat: 'yy-mm-dd',
		onSelect: function(DATE)
			{
				$('#dateto').val($.datepicker.parseDate("yy-mm-dd",DATE).getFormatedString());
				$('#dateto').attr('date',DATE);
			}
	});
}

function renderGuestType(objArray){
	var txt = "<tr><td ><input name=\"gtype\" type=\"checkbox\" value=\"all\" " +
	"onclick=\"checkAll()\"/>All</td>";
	var guesttype = objArray;
	for(var i=0;i<guesttype.length;i++){
		if((i+1)%3!=0){
			txt +="<td ><input name=\"gtype\" type=\"checkbox\" " +
			"value=\""+guesttype[i]["id"]+"\" onclick=\"nodeCheck("+(i+1)+")\"/>"+
			guesttype[i]["title"]+"</td>";
		}else{
			txt +="</tr><tr><td ><input name=\"gtype\" type=\"checkbox\" " +
			"value=\""+guesttype[i]["id"]+"\" onclick=\"nodeCheck("+(i+1)+")\"/>"+
			guesttype[i]["title"]+"</td>";
		}
	}
	txt+= "</tr>";
	$("#gtList").append(txt);
}

function renderRoomType(objArray){
	for ( var i = 0; i < objArray.length; i++) {
		$("#roomtype").append( $("<option>").val(objArray[i]['id']).html(objArray[i]['shortName']));	
	}
}

function swicth(name){
	if(name == "gtype_on"){
		$("[name=gtype_off]").attr('checked', false);
	}else if(name == "gtype_off"){
		$("[name=gtype_on]").attr('checked', false);
	}
}

function checkAll(){
	var ischeck = $("#gtList td [name=gtype]").first().is(":checked");
		for(var i=0;i<$("#gtList td [name=gtype]").size();i++){
			$($('input[name=gtype]')[i]).attr('checked', ischeck);
		}
}

function searchdate(){
	waitingDialog({});
	$("#autofill").css("display","");
	$("[name=firsttd]").removeClass("secondtd");
	$("#fillbtn").css("display","");
	var selectedroomtype = $("#roomtype :selected").val();
	if($("#datefrom").val() == "" || $("#dateto").val() == ""){
		simpleDialog("please input data");
		return;
	}else{
		var from = $("#from").attr("date");
		var to = $("#to").attr("date");
	}

	var txt = "";
	var roomtype = SharedData.Roomtype;
	for(var i=0;i<roomtype.length;i++){
		if(roomtype[i]['id'] == selectedroomtype){
			var roomtypedata = roomtype[i]; 
			break;
		}
	}
	var span = daysBetween(new Date(from),new Date(to));
	for(var i=0;i<span;i++){
		var thisdate = new Date(from).addDate(i);
			txt +="<tr name=\"rttable\" date=\""+thisdate.toSystemFormat()+"\">"+
                    "<td class=\"secondtd firstcol\"><span>"+thisdate.toFormatString("dd-MM-yyyy")+"</span></td>"+
                    "<td class=\"secondtd\"><span>"+ShortDay[thisdate.getDay()]+"</span></td>"+
                    "<td class=\"secondtd\"><span>"+roomtypedata["basePrice"]+"</span></td>"+
                    "<td class=\"secondtd\"><span>"+roomtypedata["upchargeperson"]+"</span></td>"+
                    "<td class=\"secondtd\"><span>"+roomtypedata["extraBedPrice"]+"</span></td>"+
                    "<td class=\"secondtd\"><input class=\"inputtextright\" group=\"pricepernight\" type=\"text\" size=\"8\" value=\"0\"></td>"+
                    "<td class=\"secondtd\"><input class=\"inputtextright\" group=\"upchargeperson\" type=\"text\" size=\"8\" value=\"0\"></td>"+
                    "<td class=\"secondtd\"><input class=\"inputtextright\" group=\"extrabedprice\" type=\"text\" size=\"8\" value=\"0\"></td>"+
                    "<td class=\"secondtd\"><select name=\"adult\"></select></td>" +
                    "<td class=\"secondtd\"><select name=\"child\"></select></td>" +
                    "<td class=\"secondtd\"><input type=\"checkbox\" name=\"breakfast\"/></td>" +
                    "<td class=\"secondtd lastcol\">&nbsp;</td>"+
                "</tr>";
	}
	$("[name=rttable]").remove();
	$("#rtList").append(txt);
	$("[group=pricepernight]").val(roomtypedata["basePrice"]);
	$("[lable=pricepernight]").html(roomtypedata["basePrice"]);
	$("[group=upchargeperson]").val(roomtypedata["upchargeperson"]);
	$("[lable=upchargeperson]").html(roomtypedata["upchargeperson"]);
	$("[group=extrabedprice]").val(roomtypedata["extraBedPrice"]);
	$("[lable=extrabedprice]").html(roomtypedata["extraBedPrice"]);
	fillAdult(roomtypedata["MaxOccupancy"]);
	fillChild(roomtypedata["MaxOccupancy"]);
	$("#exadult").val(1);
	$("#exchild").val(0);
	$("#exBreakfast").attr("checked",false);
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function addflexiblepackage(id){
	waitingDialog({});
	var packagename = $("#packagename").val();
	var description = $("#description").val();
	var datefrom = $("#from").attr("date");
	var dateto = $("#to").attr("date");
	var guesttype = "";
	for(var i=1;i<$("#gtList td [name=gtype]").size();i++){
		if($($("#gtList td [name=gtype]")[i]).is(":checked")){
			guesttype += $($("#gtList td [name=gtype]")[i]).val() +",";
		}
	}
	guesttype = guesttype.substring(0,guesttype.length-1);
	var status = $("[name=gtype_on]").is(":checked");
	var dateArray = new Array();
	var ppnArray = new Array();
	var ucppArray = new Array();
	var exbedArray = new Array();
	var adultArray = new Array();
	var childArray = new Array();
	var breakfastArray = new Array();
	var pId = new Array();
	var roomtype = $("#roomtype :selected").val();
	for(var i=0;i<$("[name=rttable]").size();i++){
		pId[i] = $($("[name=rttable]")[i]).attr("pId");
		dateArray[i] = $($("[name=rttable]")[i]).attr("date");
		ppnArray[i] = $($("[name=rttable]")[i]).find("[group=pricepernight]").val();
		ucppArray[i] = $($("[name=rttable]")[i]).find("[group=upchargeperson]").val();
		exbedArray[i] = $($("[name=rttable]")[i]).find("[group=extrabedprice]").val();
		adultArray[i] = $($("[name=rttable]")[i]).find("[name=adult]").val();
		childArray[i] = $($("[name=rttable]")[i]).find("[name=child]").val();
		breakfastArray[i] = $($("[name=rttable]")[i]).find("[name=breakfast]").is(":checked");
	}
	
	if($("[name=maxEntries]").val() == null){
		var line = 10;
	}else{
		var line = $("[name=maxEntries]").val();
	}
	if($("[name=selectpage]").val() == null){
		var pagePointer = 1; 
	}else{
		var pagePointer = $("[name=selectpage]").val(); 
	}
	var func = "addflexiblepackage";
	if(id != null){
		func = "editflexiblepackage";
	}
	var data = {func : func,
			id : id,
			packagename : packagename,
			description : description,
			datefrom : datefrom,
			dateto : dateto,
			guesttype : guesttype,
			status : status,
			pId : pId.toString(),
			dateArray : dateArray.toString(),
			ppnArray : ppnArray.toString(),
			ucppArray : ucppArray.toString(),
			exbedArray : exbedArray.toString(),
			adultArray : adultArray.toString(),
			childArray : childArray.toString(),
			breakfastArray : breakfastArray.toString(),
			roomtype : roomtype,
			offset: (line*pagePointer)-line,
			line: line,
			pagePointer: pagePointer
			};
	var url = "/flexiblepackageservice";
	simpleservice(url,data,AddSuccess);
}

function AddSuccess(data){
	if($("#tabHeader_1").attr("class") == "tabActiveHeader"){
		$("#addtableFlex").css("display","none");
		$("#tableFlex").css("display","");
	}else{
		$("#addtableFlexArchived").css("display","none");
		$("#tableFlexArchived").css("display","");
	}
	
	showFlexiblePackageList(data);
}

function autofill(){
	waitingDialog({});
	var exppn = $("#exppn").val();
	var exucp = $("#exucp").val();
	var exexbed = $("#exexbed").val();
	var adult = $("#exadult").val();
	var child = $("#exchild").val();
	$("[group=pricepernight]").val(exppn);
	$("[group=upchargeperson]").val(exucp);
	$("[group=extrabedprice]").val(exexbed);
	$("[name=adult]").val(adult);
	$("[name=child]").val(child);
	var isBreakfast = $("#exBreakfast").is(":checked")
	$("[name=breakfast]").attr("checked",isBreakfast);
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function cancelFlex(){
	if($("#tabHeader_1").attr("class") == "tabActiveHeader"){
		$("#addtableFlex").css("display","none");
		$("#tableFlex").css("display","");
	}else{
		$("#addtableFlexArchived").css("display","none");
		$("#tableFlexArchived").css("display","");
	}
}

function fillAdult(adult){
	for ( var i = 1; i <= adult; i++) {
		$("[name=adult]").append( $("<option>").val(i).html(i));
	}
}

function fillChild(child){
	for ( var i = 0; i < child; i++) {
		$("[name=child]").append( $("<option>").val(i).html(i));	
	}
}

function CheckLoadFunction(){
	if($("#tabHeader_1").attr("class") == "tabActiveHeader"){
		showFlexiblePackage();
	}else{
		showArchivedFlexiblePackage();
	}
}

function showFlexiblePackage(id){
		if(id == null){
			if($("[name=maxEntries]").val() == null){
				var line = 10;
			}else{
				var line = $("[name=maxEntries]").val();
			}
			if($("[name=selectpage]").val() == null){
				var pagePointer = 1; 
			}else{
				var pagePointer = $("[name=selectpage]").val(); 
			}
		}else if(id == "next"){
			var line = $("[name=maxEntries]").val();
			var pagePointer = parseInt($("[name=selectpage]").val())+1;
		}else if(id == "previous"){
			var line = $("[name=maxEntries]").val();
			var pagePointer = parseInt($("[name=selectpage]").val())-1;		
		}
		var link = "/flexiblepackageservice";
		var data = { func: "getAllFlexible4Admin",
					offset: (line*pagePointer)-line,
					line: line,
					pagePointer: pagePointer
						}
		simpleservice(link,data,showFlexiblePackageList);
}

function showFlexiblePackageList(data){
	var objArray2 = new Array();
	objArray2 = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray2);
	if(checkLogOut)
		return;
	var sumtext = "";
	var text = "";
	var pageAmount = objArray2["pageAmount"];
	var line = objArray2["lineAmount"];
	var pagePointer = objArray2["pageNumber"];
	var objArray = objArray2["data"];
	$("#listsize").html("&nbsp;("+objArray2["dataAmount"]+")");
	var lineNumber = (line * pagePointer) - (line-1) ;
	
	if(objArray.length == 0){
		text = "<tr><td colspan=\"7\" style=\"border-top:1px #D6D7D5 solid;border-bottom:1px #D6D7D5 solid;\">"+nodata+"</td></tr>";
		sumtext += text;
	}else{
		for(var i = 0;i< objArray.length+1;i++){
				if(i != objArray.length ){
					var from = new Date(objArray[i]['from']).getFormatedString();
					var to = new Date(objArray[i]['to']).getFormatedString();
					text = "<tr id=\"row_"+objArray[i]['id']+"\" style=\"border: 0px;\"> " +
							"<td id=\"col_1\" align=\"center\"> "+(lineNumber+i)+". </td>"+
							"<td><input type=\"checkbox\" id=\"id_"+i+"\" name=\"ids\" value=\""+objArray[i]['id']+"\"> </td>"+
							"<td align=\"left\"> "+objArray[i]['name']+" </td>"+
							"<td align=\"left\">"+objArray[i]['roomtype']+" </td>"+
				            "<td align=\"center\">"+from+" - "+to+"</td> "+
							"<td align=\"center\"><a href=\"#\" onclick=\"editFlexPackege("+objArray[i]['id']+")\">Edit</a></td>"+
							"<td align=\"center\"><a href=\"#\" onclick=\"changeStatus("+objArray[i]['id']+") \"> " +
							"<span id =status"+objArray[i]['id']+">"+objArray[i]['status']+"</a>" +
							"</td>" +
							"</tr>";
					sumtext += text;
				}else{
					text = "<tr>"+
					"<td colspan=\"13\" style=\"padding:0;\">"+
					"<table class=\"tablefoot\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
					"<tbody>"+
						"<tr>"+
							"<td width=\"33%\" align=\"left\">"+foor_page+"&nbsp;"+
								"<select name=\"selectpage\" onchange=\"showFlexiblePackage()\">"+
								"</select>&nbsp;"+foor_of+"&nbsp;<span id=\"pageAmount\">1</span>"+
							"</td>"+
							"<td width=\"31%\" align=\"center\">"+foor_view+
								"<select name=\"maxEntries\" onchange=\"showFlexiblePackage()\">"+
									"<option style=\"color:#000000\"  value=\"10\">10</option>"+
									"<option style=\"color:#000000\"  value=\"20\">20</option>"+
									"<option style=\"color:#000000\"  value=\"50\">50</option>"+
									"<option style=\"color:#000000\"  value=\"100\">100</option>"+
									"<option style=\"color:#000000\"  value=\"100000\">All</option>"+
								"</select>"+foor_rpp+" </td>" +
								"<td width=\"36%\" align=\"right\"><span id=\"previous\">&lt;&lt;"+foor_pre+"</span> |" +
								" <span id=\"next\">"+foor_next+"&gt;&gt;</span></td></tr>"+
								"</tbody></table></td></tr>";
					sumtext += text;
				}
		}
	}
	$("#showList tr").not($("#showList").find('.tablehead').parent()).remove();
	$("#showList").append(sumtext);
	$("#pageAmount").text(pageAmount);
	if(pagePointer+1 <= pageAmount){
		$("#next").attr("onclick","showFlexiblePackage(id)");
		$("#next").html("<a href=\"#\">"+foor_next+"&gt;&gt;</a>");
	}
	if(pagePointer > 1){
		$("#previous").attr("onclick","showFlexiblePackage(id)");
		$("#previous").html("<a href=\"#\">&lt;&lt;"+foor_pre+"</a>");
	}
	$("[name=maxEntries]").val(line);
	for ( var i = 0; i < pageAmount; i++) {
		$("[name=selectpage]").append(
				$("<option>").val((i+1)).html((i+1)));
		}
	$("[name=selectpage]").val(pagePointer);
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function changeStatus(id){
	waitingDialog({});
	var url = "/flexiblepackageservice";
	var data = { func : "changeStatus",
			id : id
		}
	simpleserviceWithArgs(url,data,changeStatusSuccess);
}

function changeStatusSuccess(data){
	var objArray = new Array();
	objArray = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray);
	if(checkLogOut)
		return;
	$("#status"+objArray["id"]).text(objArray["status"]);
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function showArchivedFlexiblePackage(id){
	if(id == null){
		if($("[name=maxEntries]").val() == null){
			var line = 10;
		}else{
			var line = $("[name=maxEntries]").val();
		}
		if($("[name=selectpage]").val() == null){
			var pagePointer = 1; 
		}else{
			var pagePointer = $("[name=selectpage]").val(); 
		}
	}else if(id == "next"){
		var line = $("[name=maxEntries]").val();
		var pagePointer = parseInt($("[name=selectpage]").val())+1;
	}else if(id == "previous"){
		var line = $("[name=maxEntries]").val();
		var pagePointer = parseInt($("[name=selectpage]").val())-1;		
	}
	var link = "/flexiblepackageservice";
	var data = { func: "getAllFlexibleArchive4Admin",
				offset: (line*pagePointer)-line,
				line: line,
				pagePointer: pagePointer
					}
	simpleservice(link,data,showFlexiblePackageArchiveList);
}

function showFlexiblePackageArchiveList(data){
	var objArray2 = new Array();
	objArray2 = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray2);
	if(checkLogOut)
		return;
	var sumtext = "";
	var text = "";
	var pageAmount = objArray2["pageAmount"];
	var line = objArray2["lineAmount"];
	var pagePointer = objArray2["pageNumber"];
	var objArray = objArray2["data"];
	$("#listsize").html("&nbsp;("+objArray2["dataAmount"]+")");
	var lineNumber = (line * pagePointer) - (line-1) ;
	
	if(objArray.length == 0){
		text = "<tr><td colspan=\"6\" style=\"border-top:1px #D6D7D5 solid;border-bottom:1px #D6D7D5 solid;\">"+nodata+"</td></tr>";
		sumtext += text;
	}else{
		for(var i = 0;i< objArray.length+1;i++){
				if(i != objArray.length ){
					var from = new Date(objArray[i]['from']).getFormatedString();
					var to = new Date(objArray[i]['to']).getFormatedString();
					text = "<tr id=\"row_"+objArray[i]['id']+"\" style=\"border: 0px;\"> " +
							"<td id=\"col_1\" align=\"center\"> "+(lineNumber+i)+". </td>"+
							"<td><input type=\"checkbox\" name=\"archivebox\" value=\""+objArray[i]['id']+"\"> </td>"+
							"<td align=\"left\"> "+objArray[i]['name']+" </td>"+
							"<td align=\"left\">"+objArray[i]['roomtype']+" </td>"+
				            "<td align=\"center\">"+from+" - "+to+"</td> "+
							"<td align=\"center\"><a href=\"#\" onclick=\"editFlexPackege("+objArray[i]['id']+")\">Edit</a></td>"+
							"<span id =status"+objArray[i]['id']+">"+objArray[i]['status']+"</a>" +
							"</td>" +
							"</tr>";
					sumtext += text;
				}else{
					text = "<tr>"+
					"<td colspan=\"6\" style=\"padding:0;\">"+
					"<table class=\"tablefoot\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
					"<tbody>"+
						"<tr>"+
							"<td width=\"33%\" align=\"left\">"+foor_page+"&nbsp;"+
								"<select name=\"selectpage\" onchange=\"showArchivedFlexiblePackage()\">"+
								"</select>&nbsp;"+foor_of+"&nbsp;<span id=\"pageAmount\">1</span>"+
							"</td>"+
							"<td width=\"31%\" align=\"center\">"+foor_view+
								"<select name=\"maxEntries\" onchange=\"showArchivedFlexiblePackage()\">"+
									"<option style=\"color:#000000\"  value=\"10\">10</option>"+
									"<option style=\"color:#000000\"  value=\"20\">20</option>"+
									"<option style=\"color:#000000\"  value=\"50\">50</option>"+
									"<option style=\"color:#000000\"  value=\"100\">100</option>"+
									"<option style=\"color:#000000\"  value=\"100000\">All</option>"+
								"</select>"+foor_rpp+" </td>" +
								"<td width=\"36%\" align=\"right\"><span id=\"previous\">&lt;&lt;"+foor_pre+"</span> |" +
								" <span id=\"next\">"+foor_next+"&gt;&gt;</span></td></tr>"+
								"</tbody></table></td></tr>";
					sumtext += text;
				}
		}
	}
	$("#showListArchived tr").not($("#showListArchived").find('.tablehead').parent()).remove();
	$("#showListArchived").append(sumtext);
	$("#pageAmount").text(pageAmount);
	if(pagePointer+1 <= pageAmount){
		$("#next").attr("onclick","showArchivedFlexiblePackage(id)");
		$("#next").html("<a href=\"#\">"+foor_next+"&gt;&gt;</a>");
	}
	if(pagePointer > 1){
		$("#previous").attr("onclick","showArchivedFlexiblePackage(id)");
		$("#previous").html("<a href=\"#\">&lt;&lt;"+foor_pre+"</a>");
	}
	$("[name=maxEntries]").val(line);
	for ( var i = 0; i < pageAmount; i++) {
		$("[name=selectpage]").append(
				$("<option>").val((i+1)).html((i+1)));
		}
	$("[name=selectpage]").val(pagePointer);
	if($("#loadingScreen").is(":visible")) closeWaitingDialog();
}

function toggleSelect(){
	if($("#showList tr [type=checkbox]")[0].checked == true){
		for(var i = 0;i< $("#showList tr [type=checkbox]").size();i++){
			$("#showList tr [type=checkbox]")[i].checked = true;
		}
	}else{
		for(var i = 0;i< $("#showList tr [type=checkbox]").size();i++){
			$("#showList tr [type=checkbox]")[i].checked = false;
		}
	}
}

function deleteFixedPackage(){
	var listCheckBox = "";
	var line = $("[name=maxEntries]").val();
	var pagePointer = $("[name=selectpage]").val();
	for(var i = 0;i<$('tr [type=checkbox][id*=id_]').length;i++){
		if($($('tr [type=checkbox][id*=id_]')[i]).is(":checked")){	
			listCheckBox += $($('tr [type=checkbox][id*=id_]')[i]).attr("value")+",";
		}
	}
	var url = "/flexiblepackageservice";
	var data = { func : "del",
			id : listCheckBox.substring(0,listCheckBox.length - 1),
			offset: (line*pagePointer)-line,
			line: line,
			pagePointer: pagePointer
		}
	simpleserviceWithArgs(url,data,showFlexiblePackageList);
}

function restorearchived(){
	var listCheckBox = "";
	var line = $("[name=maxEntries]").val();
	var pagePointer = $("[name=selectpage]").val();
	for(var i = 0;i<$('tr [type=checkbox][name=archivebox]').length;i++){
		if($($('tr [type=checkbox][name=archivebox]')[i]).is(":checked")){	
			listCheckBox += $($('tr [type=checkbox][name=archivebox]')[i]).attr("value")+",";
		}
	}
	var url = "/flexiblepackageservice";
	var data = { func : "restore",
			id : listCheckBox.substring(0,listCheckBox.length - 1),
			offset: (line*pagePointer)-line,
			line: line,
			pagePointer: pagePointer
		}
	simpleserviceWithArgs(url,data,showFlexiblePackageArchiveList);
}

function changearchived(id){
	var listCheckBox = "";
	var line = $("[name=maxEntries]").val();
	var pagePointer = $("[name=selectpage]").val();
	for(var i = 0;i<$('tr [type=checkbox][id*=id_]').length;i++){
		if($($('tr [type=checkbox][id*=id_]')[i]).is(":checked")){	
			listCheckBox += $($('tr [type=checkbox][id*=id_]')[i]).attr("value")+",";
		}
	}
	var url = "/flexiblepackageservice";
	var data = { func : "archived",
			id : listCheckBox.substring(0,listCheckBox.length - 1),
			offset: (line*pagePointer)-line,
			line: line,
			pagePointer: pagePointer
		}
	simpleserviceWithArgs(url,data,showFlexiblePackageList);
}